// request 是我们封装的一个网络请求库
import request from './../utils/request';
import config from './../config';
import {
    empty
} from './../utils/helper';

const url = config.service.host;
const obj = {
    success: function(res) {
        console.log(res)
    },
    fail: function(res) {
        message(res.msg)
    },
    complete: function(res) {}
};

//获取律师信息
export function getLawyerInfo(params, cb = {}) {
    const f = Object.assign(obj, cb);
    request(`${url}/Index/getLawyerInfo`, params).then((res) => {
        if (typeof res == "object") {
            if (res.status == "OK") {
                f.success(res);
            } else {
                f.fail(res);
            }
            f.complete(res);
        } else {
            console.warn(res);
        }
    })
}

//获取分享信息
export function getShareInfo(params, cb = {}) {
    const f = Object.assign(obj, cb);
    request(`${url}/Share/getShareInfo`, params).then((res) => {
        if (typeof res == "object") {
            if (res.status == "OK") {
                f.success(res);
            } else {
                f.fail(res);
            }
            f.complete(res);
        } else {
            console.warn(res);
        }
    })
}

//催单
export function Evaluation(params, cb = {}) {
    const f = Object.assign(obj, cb);
    request(`${url}/Chat/evaluation`, params).then((res) => {
        if (typeof res == "object") {
            if (res.status == "OK") {
                f.success(res);
            } else {
                f.fail(res);
            }
            f.complete(res);
        } else {
            console.warn(res);
        }
    })
}

// 获取订单详情
export function getOrderInfo(params, cb = function() {}) {
    request(`${url}/Order/orderInfo`, params).then((res) => {
        cb(res)
    })
}

// 发送消息
export function sendMessage(params, cb = function() {}) {
    request(`${url}/Chat/submitSendMessage`, params).then((res) => {
        cb(res)
    })
}

// 获取聊天记录
export function getMessage(params, cb = function() {}) {
    request(`${url}/Chat/getMessage`, params, false).then((res) => {
        cb(res)
    })
}